import { createStore } from 'vuex'
import createPersistedState from "vuex-persistedstate"

export default createStore({
    state: {
        id: '',
        userAccount: '',
        userAvatar: '',
        userName: '',
        userRole: '',
        gender: '',
        phone: '',
    },
    mutations: {
        setUserAccount: (state, payload) => {
            state.userAccount = payload.value;
        },
        setId: (state,payload) => {
            state.id = payload.value
        },
        setUserAvatar: (state,payload) => {
            state.userAvatar = payload.value
        },
        setUserName: (state,payload) => {
            state.userName = payload.value
        },
        setUserRole: (state,payload) => {
            state.userRole = payload.value
        },
        setGender: (state,payload) =>{
            state.gender = payload.value
        },
        setPhone: (state,payload) =>{
            state.phone = payload.value
        },

    },
    actions: {
    },
    modules: {
    },
    plugins:[createPersistedState({
        storage: window.sessionStorage,
        reducer(val){
            return{
                id: val.id,
                userAccount: val.userAccount,
                userAvatar: val.userAvatar,
                userName: val.userName,
                userRole: val.userRole,
                gender: val.gender,
                phone: val.phone,
            }
        }
    })]
})